package com.learn.jdk8.lambda02;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {

    private static Comparator<Integer> comparator(){
        return new  Comparator<Integer>(){

            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
    }

    private static Comparator<Integer> comparator1(){
        return (Integer o1,Integer o2)-> o2.compareTo(o1);
    }

    public static void main(String[] args) {
        Comparator<Integer> cpt = comparator();

        TreeSet<Integer> set = new TreeSet<>(cpt);

        set.add(22);
        set.add(6);
        set.add(88);
        set.add(8);
        set.add(10);
        set.add(12);

        System.out.println(set);

        System.out.println("===============================");

        Comparator<Integer> cpt1 = comparator1();

        TreeSet<Integer> set1 = new TreeSet<>(cpt1);

        set1.add(22);
        set1.add(6);
        set1.add(88);
        set1.add(8);
        set1.add(10);
        set1.add(12);

        System.out.println(set1);

        //todo 无类型推断
        Comparator<Integer> cpt2 =  (Integer o1,Integer o2)-> o2.compareTo(o1);

        //todo 有类型推断
        Comparator<Integer> cpt3 =  ( o1, o2)-> o2.compareTo(o1);

    }


}
